package trangchu;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;

import chucnang.ButtonTabComponent;
import dangnhap.FromDangNhap;
import danhmuc.DonViTinh;
import danhmuc.HangHoa;
import danhmuc.KhachHang;
import danhmuc.NhaPhanPhoi;
import danhmuc.NhanVien;
import danhmuc.NhomHang;
import danhmuc.TiGia;
import chucnang.MuaHang;
public class DanhMuc extends JPanel implements ActionListener {
	private JToolBar tbr;
	private JButton btnkhachhang,btnnhaphanphoi,btnnhomhang,btnhanghoa,btntigia,btndonvitinh,btnnhanvien,btnkho;
	private TrangChu trangchu;
	
	
	
	public DanhMuc(TrangChu trangchu){
		
		this.setLayout(new FlowLayout(FlowLayout.LEFT));
		this.trangchu = trangchu;
		this.tbr = new JToolBar();
		this.add(this.tbr);
		this.tbr.setOrientation(JToolBar.HORIZONTAL);
		this.btnkhachhang = new JButton("Khách Hàng",new ImageIcon(FromDangNhap.rootPath+"images/khachhang.gif"));
		this.btnkhachhang.setVerticalTextPosition(JButton.BOTTOM);
		this.btnkhachhang.setHorizontalTextPosition(JButton.CENTER);
		
		this.tbr.add(this.btnkhachhang);
		this.tbr.setOrientation(JToolBar.HORIZONTAL);
		this.btnnhaphanphoi = new JButton("Nhà Phân Phối",new ImageIcon(FromDangNhap.rootPath+"images/nhaphanphoi.gif"));
		this.btnnhaphanphoi.setVerticalTextPosition(JButton.BOTTOM);
		this.btnnhaphanphoi.setHorizontalTextPosition(JButton.CENTER);
		this.tbr.add(this.btnnhaphanphoi);
		this.tbr.setOrientation(JToolBar.HORIZONTAL);
		this.btnnhomhang = new JButton("Nhóm Hàng",new ImageIcon(FromDangNhap.rootPath+"images/nhomhang.gif"));
		this.btnnhomhang.setVerticalTextPosition(JButton.BOTTOM);
		this.btnnhomhang.setHorizontalTextPosition(JButton.CENTER);
		this.tbr.add(this.btnnhomhang);
		this.tbr.setOrientation(JToolBar.HORIZONTAL);
		this.btnhanghoa = new JButton("Hàng Hóa",new ImageIcon(FromDangNhap.rootPath+"images/hanghoa.gif"));
		this.btnhanghoa.setVerticalTextPosition(JButton.BOTTOM);
		this.btnhanghoa.setHorizontalTextPosition(JButton.CENTER);
		this.tbr.add(this.btnhanghoa);
		this.tbr.setOrientation(JToolBar.HORIZONTAL);
		this.btnkho = new JButton("Kho",new ImageIcon(FromDangNhap.rootPath+"images/kho.gif"));
		this.btnkho.setVerticalTextPosition(JButton.BOTTOM);
		this.btnkho.setHorizontalTextPosition(JButton.CENTER);
		this.tbr.add(this.btnkho);
		this.tbr.setOrientation(JToolBar.HORIZONTAL);
		this.btntigia = new JButton("Tỉ Giá",new ImageIcon(FromDangNhap.rootPath+"images/tygia.gif"));
		this.btntigia.setVerticalTextPosition(JButton.BOTTOM);
		this.btntigia.setHorizontalTextPosition(JButton.CENTER);
		this.tbr.add(this.btntigia);
		this.tbr.setOrientation(JToolBar.HORIZONTAL);
		this.btndonvitinh = new JButton("Đơn Vị Tính",new ImageIcon(FromDangNhap.rootPath+"images/donvitinh.gif"));
		this.btndonvitinh.setVerticalTextPosition(JButton.BOTTOM);
		this.btndonvitinh.setHorizontalTextPosition(JButton.CENTER);
		this.tbr.add(this.btndonvitinh);
		this.tbr.setOrientation(JToolBar.HORIZONTAL);
		this.tbr.setOrientation(JToolBar.HORIZONTAL);
		this.btnnhanvien = new JButton("Nhân Viên",new ImageIcon(FromDangNhap.rootPath+"images/nhanvien.gif"));
		this.btnnhanvien.setVerticalTextPosition(JButton.BOTTOM);
		this.btnnhanvien.setHorizontalTextPosition(JButton.CENTER);
		this.tbr.add(this.btnnhanvien);
		this.tbr.setOrientation(JToolBar.HORIZONTAL);
		
		
	// su kien
			this.btnkhachhang.addActionListener(this);
			this.btnnhaphanphoi.addActionListener(this);
			this.btnnhomhang.addActionListener(this);
			this.btnhanghoa.addActionListener(this);
			this.btndonvitinh.addActionListener(this);
			this.btntigia.addActionListener(this);
			this.btnnhanvien.addActionListener(this);
		}
	
		@Override
		public void actionPerformed(ActionEvent e) {
			if(e.getSource()== this.btnkhachhang){
				this.trangchu.tbnPaneCenter.add("Khách Hàng",new KhachHang(trangchu));	
			}
			if(e.getSource()== this.btnnhaphanphoi){
				this.trangchu.tbnPaneCenter.add("Nhà Phân Phối",new NhaPhanPhoi(trangchu));
			}
			if(e.getSource()== this.btnnhomhang){
				this.trangchu.tbnPaneCenter.add("Nhóm Hàng",new NhomHang(trangchu));
			}
			if(e.getSource()== this.btnhanghoa){
				this.trangchu.tbnPaneCenter.add("Hàng Hóa",new HangHoa(trangchu));
			}
			if(e.getSource()== this.btndonvitinh){
				this.trangchu.tbnPaneCenter.add("Đơn Vị Tính",new DonViTinh(trangchu));
			}
			if(e.getSource()== this.btntigia){
				this.trangchu.tbnPaneCenter.add("Tỉ Giá",new TiGia(trangchu));
			}
			if(e.getSource()== this.btnnhanvien){
				this.trangchu.tbnPaneCenter.add("Nhân Viên",new NhanVien(trangchu));
			}
			int count = this.trangchu.tbnPaneCenter.getTabCount();
			for(int i=0;i<count;i++){
				this.trangchu.tbnPaneCenter.setTabComponentAt(i, new ButtonTabComponent(this.trangchu.tbnPaneCenter));
				
			}
		}
	}


